$(function () {
    //加载菜单
   $.ajax({
       type:"get",
       contentType: 'application/json',
       url: "/main/index",
       dataType: "json",
       success: function (data) {
           if(data.code == 1 && data.code != undefined){
               $("#userName").html(data.userName);
               var menus = data.menus;
               var html = '';
               for(var menu in menus){
                    html += '<li class="layui-nav-item"> <a class="javascript:;" href="javascript:;"> <i class='+menus[menu].permissionIcon+' style="top: 3px;"></i><cite>'+menus[menu].permissionName+'</cite> </a><dl class="layui-nav-child">';
                    var list = menus[menu].list
                    for(var m in list){
                        html += '<dd class=""> <a href="javascript:;" _href='+list[m].menuHref+' menuId='+list[m].id+'> <cite>'+list[m].permissionName+'</cite> </a> </dd>\n';
                        var id = list[m].id;
                        sessionStorage.setItem(id+'add',list[m].add);
                        sessionStorage.setItem(id+'del',list[m].del);
                        sessionStorage.setItem(id+'edit',list[m].edit);
                        sessionStorage.setItem(id+'query',list[m].query);
                    }
                    html += '</dl></li>';
               }
           }else if(data == 9999 && data != undefined){
               window.location.href = "/login_toLogin";
           }else if(data.code == 3 && data.code != undefined){
               window.location.href = "/login_toLogin";
           }
           html += '<li class="layui-nav-item" style="height: 30px; text-align: center"> </li>';
           $("#menu").html(html);
           element.init();

       }
   })
});

